<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>倒计时效果</title>
    <style>
        #root {
            background-color: palevioletred;
            width: 200px;
            height: 200px;
            margin: 0 auto;
        }
        h1 {
           
            /* width: 170px; */
            background-color: aqua;
            text-align: center;
            height: 40px;
            line-height: 40px;

        }
       .time {
        background-color: gold;
        width: 150px;
        margin: 0 auto;
        text-align: center;
       }
    </style>
</head>

<body>
    <div id="root">
        <h1>京东秒杀</h1>
        <div style="background-color: green; text-align: center;">倒计时</div>
        <div class="time">01:11:01</div>
    </div>
</body>
<script>
    let HH=2
    let mm=0
    let ss=0
   let time= document.querySelector('.time')
    let interval=setInterval(()=>{
        if(HH===0 &&ss === 0 && mm===0) {
        time.innerHTML=`00:00:00`
        return
       }
        // console.log('你好'+Date.now())
       let s= ss===0 ? 59 : ss-1;
       let m= ss!==0 ? mm :( (mm!==0) ? mm-1 : 59 )
       let h= m===mm ? HH :(mm!==0 ?  HH : ((HH-1)>=1 ? HH-1 : 0))
     
        time.innerHTML=`${h> 9 ? h :`0${h}`}:${m>9 ? m :`0${m}`}:${s>9 ? s:`0${s}`}`
        mm=m
        ss=s
        HH=h
       
      
    },10)
</script>

</html>